;chez-scheme 无穷流定义就死循环了，只好按chez 文档修改无穷流实现方式。

(define stream-car 
    (lambda (s) (car (force s)))
)
(define stream-cdr 
    (lambda (s) (cdr (force s)))
)


(define (stream-ref s n)
    (if (= n 0)
        (stream-car s)
        (stream-ref (stream-cdr s) (- n 1))
    )
)

(define (print-stream stream n)
    (define (print-item s count)
        (if (> count n)
            `done
            (begin
                (display (stream-car s))
                (display ",")
                (print-item (stream-cdr s) (+ count 1))
            )
        )
    )
    (newline)
    (display "s=")
    (print-item stream 0)
)

(define counters
    (let next ([n 1])
        (delay (cons n (next (+ n 1))))
    )
)

(define (stream-add s1 s2)
    (delay 
        (cons 
            (+ (stream-car s1) (stream-car s2))
            (stream-add (stream-cdr s1) (stream-cdr s2))
        )
    )
)




(define p2
    
    (delay 
        (cons 0 (stream-add counters p2))
    )
    
)

(define p3 (stream-cdr p2))
(print-stream counters 10)
(newline)
(print-stream p3 10)
(exit)